package com.wkk.controller;

import com.wkk.entity.Coach;
import com.wkk.entity.Course;
import com.wkk.service.CoachService;
import com.wkk.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 该控制层，用于实现欢迎页的信息显示，课程信息、教练信息
 */
@Controller
public class HomeController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private CoachService coachService;

    //进入主页获取信息
    @RequestMapping("/")
    public ModelAndView indexPageInfo(){
        ModelAndView mav = new ModelAndView("index");
        //获取所有公共课信息
        List<Course> commentCourses = courseService.selectListByMoldOrTeacher("公共课");
        mav.addObject("commentCourses",commentCourses);
        //获取特色课信息
        List<Course> specialCourses = courseService.selectListByMoldOrTeacher("特色课");
        mav.addObject("specialCourses",specialCourses);
        //获取专家培训师的所有信息
        mav.addObject("expertCoaches",coachService.selectListByMold("专家培训师"));
        //获取本年本月的教练排名信息
        List<Coach> allCoachesByMouth = coachService.selectListOrderByRank("mouth",0,0);
        mav.addObject("allCoachesByMouth",allCoachesByMouth);
        mav.addObject("theBestInMouthCoach",allCoachesByMouth.get(0));//最佳教练信息
        return mav;
    }

    @RequestMapping("/index")
    public ModelAndView indexPageInformation(){
        ModelAndView mav = new ModelAndView("index");
        mav.addObject("commentCourses",courseService.selectListByMoldOrTeacher("公共课"));
        mav.addObject("specialCourses",courseService.selectListByMoldOrTeacher("特色课"));
        mav.addObject("expertCoaches",coachService.selectListByMold("专家培训师"));
        List<Coach> allCoachesByMouth = coachService.selectListOrderByRank("mouth",0,0);
        mav.addObject("allCoachesByMouth",allCoachesByMouth);
        mav.addObject("theBestInMouthCoach",allCoachesByMouth.get(0));
        return mav;
    }

    //进入教练页面获取所有教练信息
    @RequestMapping("/trainers")
    public ModelAndView trainerPageInfo() {
        ModelAndView mav = new ModelAndView("trainers");
        //获取所有教练信息
        mav.addObject("allCoaches",coachService.selectListOrderByRank("all",0,0));
        return mav;
    }

    //进入课程页面,获取所有私教课信息
    @RequestMapping("/classes")
    public ModelAndView classPageInfo() {
        ModelAndView mav = new ModelAndView("classes");
        //获取所有课程信息
        List<Course> commentCourses = courseService.selectListByMoldOrTeacher("公共课");
        mav.addObject("commentCourses",commentCourses);
        List<Course> privateCourses = courseService.selectListByMoldOrTeacher("私教课");
        mav.addObject("privateCourses",privateCourses);
        List<Course> specialCourses = courseService.selectListByMoldOrTeacher("特色课");
        mav.addObject("specialCourses",specialCourses);
        return mav;
    }
}
